[PATCH] [LegalizeTypes][RISCV] Correctly sign-extend comparison for ATOMIC_CMP_XCHG
authorJessica Clarke <jrtc27@jrtc27.com>
Wed, 1 Apr 2020 14:50:47 +0000 (15:50 +0100)
committerGianfranco Costamagna <locutusofborg@debian.org>
Fri, 8 Jan 2021 11:48:25 +0000 (11:48 +0000)
commit408978b8b43d151f9b407d0c16210fe155bcbe93
tree569792d1eda3eb63a15e8eedad5f8a77eeaee265
parent55d1365d09154fcafc4d9c51484eb49aacde4cf1
[PATCH] [LegalizeTypes][RISCV] Correctly sign-extend comparison for ATOMIC_CMP_XCHG

Summary:
Currently, the comparison argument used for ATOMIC_CMP_XCHG is legalised
with GetPromotedInteger, which leaves the upper bits of the value
undefind. Since this is used for comparing in an LR/SC loop with a
full-width comparison, we must sign extend it. We introduce a new
getExtendForAtomicCmpSwapArg to complement getExtendForAtomicOps, since
many targets have compare-and-swap instructions (or pseudos) that
correctly handle an any-extend input, and the existing function
determines the extension of the result, whereas we are concerned with
the input.

This is related to https://reviews.llvm.org/D58829, which solved the
issue for ATOMIC_CMP_SWAP_WITH_SUCCESS, but not the simpler
ATOMIC_CMP_SWAP.

Reviewers: asb, lenary, efriedma

Reviewed By: asb

Subscribers: arichardson, hiraditya, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, jfb, PkmX, jocewei, psnobl, benna, Jim, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, evandro, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74453

Gbp-Pq: Name D74453-riscv-atomic_cmp_xchg.diff
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll